/*
 * @Description:退款记录详情
 * @Author: tao.xie
 * @Date: 2019-03-18 14:05:36
 * @Last Modified by: tao.xie
 * @Last Modified time: 2019-03-19 17:42:36
 */

<template>
  <div
    id="app"
    class="flex-v flex-vc"
  >
    <comsume-detail-main
      :icon-url="detailIcon"
      :detail-msg="detailMsg"
      :info-list="infoList"
    />
  </div>
</template>

<script>
import ConsumeDetailMain from '../components/ConsumeDetailMain'
import { getRefundAndReturnDetail } from '../api/api.js'
import getInfoListDataByState from '../state/RefundConsumeStateController.js'
import { dateFtt } from 'vue-xiaobu-utils'
import { REFUND_TRANSFER, PAY_OFFLINE, PAY_BUS, PAY_STAFF_MEAL, PAY_ONLINE, RECHARGE_BY_APP_WECHART, RECHARGE_BY_APP_ALI, RECHARGE_BY_JS_WECHART, RECHARGE_BY_UNION_WAP } from '../constants/TradeDetailType.js'
export default {
  name: 'App',
  components: {
    'comsume-detail-main': ConsumeDetailMain
  },
  data() {
    return {
      detailIcon: '',
      detailMsg: '',
      infoList: []
    }
  },
  mounted() {
    this.getDetail()
  },
  methods: {
    // 获取详情
    getDetail: async function() {
      try {
        let rs = getRefundAndReturnDetail('201812251527306711236693')
        this.parseAssociateDetailType(rs.ASSOCIATE_DETAIL_TYPE)
        // 解析换乘优惠的情况
        if (rs.TRADE_DETAIL_TYPE === REFUND_TRANSFER) {
          this.detailIcon = require('../assets/refund_transfer.png')
          this.parseTransferRefundType(rs)
        } else {
          this.detailIcon = require('../assets/refund.png')
        }
        this.infoList.concat(getInfoListDataByState(rs))
      } catch (err) { }
    },
    // 解析换乘优惠
    parseTransferRefundType: function(detailObj) {
      this.detailMsg = detailObj.ROUTE_NAME
      if (detailObj.ASSOCIATE_TRADE_TIME) {
        let copyinfolist = []
        copyinfolist.push({
          infoName: '换乘时间',
          infoValue: dateFtt('yyyy年MM月dd日 hh:mm:ss', detailObj.ASSOCIATE_TRADE_TIME)
        })
        this.infoList.concat(copyinfolist)
      }
    },
    // 解析小类型
    parseAssociateDetailType: function(associateDetailType) {
      switch (associateDetailType) {
        case PAY_OFFLINE:
          this.detailMsg = '线下消费退款'
          break
        case PAY_BUS:
          this.detailMsg = '乘车消费退款'
          break
        case PAY_STAFF_MEAL:
          this.detailMsg = '员工餐消费退款'
          break
        case PAY_ONLINE:
          this.detailMsg = '员工卡退款'
          break
        case RECHARGE_BY_APP_WECHART:
          this.detailMsg = '微信APP支付充值退款'
          break
        case RECHARGE_BY_APP_ALI:
          this.detailMsg = '支付宝支付充值退款'
          break
        case RECHARGE_BY_JS_WECHART:
          this.detailMsg = '微信JS支付充值退款'
          break
        case RECHARGE_BY_UNION_WAP:
          this.detailMsg = '银联支付充值退款'
          break
      }
    }
  }
}
</script>

<style>
.info {
  margin-top: 20px;
}
</style>
